﻿Type=Activity
Version=2.71
@EndOfDesignText@
#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: True
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.

	Dim V_KSBM As String
	Dim V_KSMC As String
	Dim V_YSBM As String
	Dim V_YSMC As String
	
	Dim FKSBM As String
	Dim FBHData As List
	
End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.

	Dim lsvXM As ListView
	Dim HttpJobTool As HttpJob
	Dim Barcode As ABZxing

End Sub

Sub Activity_Create(FirstTime As Boolean)
	Activity.LoadLayout("FormBHList")
	
	InitLayOut
	
	'RefeshList
	
	Activity.Title = "病人列表-" & V_KSBM & " " & V_KSMC
	
End Sub

Sub Activity_Resume
	If FKSBM <> V_KSBM OR FBHData.Size = 0 Then
		RefeshList
	Else
		SetYLBHList(FBHData)
	End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Private Sub InitLayOut

	lsvXM.FastScrollEnabled = True
	
	'高级菜单
	
	Activity.AddMenuItem("扫描定位","MenuItemAdv")
	Activity.AddMenuItem("手工定位","MenuItemAdv")
	
	Activity.AddMenuItem("登陆科室","MenuItemAdv")
End Sub


Sub lsvXM_ItemClick (Position As Int, Value As Object)
	Dim BHMap As Map
	
	BHMap = Value
	
	If BHMap<>Null Then
		GoXMList(BHMap)
			
	End If
	
End Sub

Sub GoXMList(ABHMap As Map)
	Dim sCYRQ As String
	If ABHMap<>Null Then
		XMList.V_BHID = ABHMap.Get("BHID")
		XMList.V_CH = ABHMap.Get("CH")
		XMList.V_XM = ABHMap.Get("XM")
		XMList.V_XB = ABHMap.Get("XB")
		XMList.V_NL = ABHMap.Get("NL")
		XMList.V_RYRQ = ABHMap.Get("RYRQ")
		
		sCYRQ = ABHMap.Get("CYRQ")
		If sCYRQ ="" Then
			XMList.V_CYRQ = 0
		Else
			XMList.V_CYRQ = sCYRQ
		End If
		
		StartActivity("XMList") 	
	
	End If

End Sub

Sub MenuItemAdv_Click
	If Sender = "手工定位" Then
		StartActivity("BHSearch")
		
	Else If Sender = "扫描定位" Then
		BHScan 	

	Else If Sender = "登陆科室" Then
		StartActivity("LoginKS") 
	End If
	
End Sub

Sub RefeshList
	If FKSBM<>V_KSBM Then
		FKSBM = V_KSBM
		
		RefreshData
	End If
End Sub

Sub RefreshData
	Dim sURL,sSession,sText,sKSBM,sYSBM,sAppType As String
	
	sText = "病人列表-" & V_KSBM & " " & V_KSMC
	
	Activity.Title = sText
	lsvXM.Clear
	
	sSession = PublicVar.GV_DesTool.Base64encrypt(PublicVar.GV_UserSession)
	
	sKSBM = PublicVar.GV_DesTool.Base64encrypt(V_KSBM)
	sYSBM = PublicVar.GV_DesTool.Base64encrypt(V_YSBM)
	sAppType = PublicVar.GV_DesTool.Base64encrypt(PublicVar.GV_AppType)
	
	sText = "Session=" & sSession & "&KSBM=" & sKSBM & "&YSBM=" & sYSBM & "&AppType=" & sAppType

	sURL = PublicVar.GetServerUrl&"/getylbhlist"
	HttpJobTool.Initialize("Job1",Me)
	HttpJobTool.PostString(sURL,sText)

	ProgressDialogShow("正在获取数据，请稍候...")	

End Sub

Sub JobDone (Job As HttpJob)
   Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
   If Job.Success = True Then
      If Job.JobName = "Job1" Then
				HttpJobSuccess(Job)
      End If
   Else
		HttpJobError(Job)
   End If
   Job.Release
End Sub


Sub HttpJobSuccess(Job As HttpJob)  
	Dim sResult,sCode,sData As String
	Dim mapResult As Map
	
	ProgressDialogHide
	sResult = Job.GetString.Trim
	
	PublicVar.GV_JSonTool.Initialize(sResult)
	mapResult = PublicVar.GV_JSonTool.NextObject
	
	sCode = mapResult.Get("Code")
	If sCode<>"0" Then
		sResult = mapResult.Get("Message")
		ToastMessageShow("获取数据失败"&CRLF &sResult, True)	
		
		PublicVar.CheckSession(sCode)
		Return
	End If
	
	sData = mapResult.Get("Data")
	If sData ="" Then
		ToastMessageShow("获取数据失败"&CRLF &"返回的数据为空", True)
		Return	
	
	End If
	
	sData = PublicVar.GV_DesTool.Base64decrypt(sData)
	PublicVar.GV_JSonTool.Initialize(sData)
	FBHData = PublicVar.GV_JSonTool.NextArray
	FKSBM = V_KSBM
	SetYLBHList(FBHData)

End Sub

Sub HttpJobError (Job As HttpJob)   
	Dim sMsg As String
	ProgressDialogHide
			
	Log("Error: " & Job.ErrorMessage)
	sMsg = "获取登陆病号数据失败."& CRLF & Job.ErrorMessage 
  ToastMessageShow(sMsg, True)
End Sub

Sub SetYLBHList(lsRecords As List)
	Dim sLine1,sLine2 As String
	Dim mapResult As Map
	lsvXM.Clear
	For i = 0 To lsRecords.Size - 1 
		mapResult = lsRecords.Get(i)
		
		sLine1 = mapResult.Get("CH") & " " & mapResult.Get("XM") & " "& mapResult.Get("XB") 
		If mapResult.Get("NL")<>"" Then
			sLine1 = sLine1 & " "& mapResult.Get("NL")&"岁" 	
		End If
		
		sLine2 = mapResult.Get("ZZYSMC") & " " & mapResult.Get("ZYH") & " "& mapResult.Get("HLMC")
		
		Dim mapReVal As Map
		mapReVal.Initialize
		
		mapReVal.Put("BHID",mapResult.Get("BHID"))
		mapReVal.Put("CH",mapResult.Get("CH"))
		mapReVal.Put("XM",mapResult.Get("XM"))
		mapReVal.Put("XB",mapResult.Get("XB"))
		mapReVal.Put("NL",mapResult.Get("NL"))
		mapReVal.Put("RYRQ",mapResult.Get("RYRQ"))
		mapReVal.Put("CYRQ",mapResult.Get("CYRQ"))
		mapReVal.Put("ZYH",mapResult.Get("ZYH"))
		
		lsvXM.AddTwoLines2(sLine1,sLine2,mapReVal)
		
	Next

End Sub

Sub BHScan
	Barcode.ABGetBarcode("Barcode", "")

End Sub

Sub Barcode_BarcodeFound(ABarcode As String, AFormatName As String)
	Dim mapResult As Map
	Dim sZYH As String 
	sZYH = ABarcode.ToUpperCase
	
	sZYH = sZYH.Replace("G","")
	sZYH = sZYH.Replace("R","")
	
  mapResult = SearchBH(sZYH)
	If mapResult<> Null Then
		ProgressDialogHide
		ToastMessageShow("找到该住院号:"&sZYH, True)			
		GoXMList(mapResult)	
	Else
		ProgressDialogHide
		ToastMessageShow("找不到该住院号:"&sZYH, True)		
	End If

End Sub

Sub Barcode_Canceled()
	ProgressDialogHide
	ToastMessageShow("取消扫描", True)
	
End Sub

Sub SearchBH(AZYH As String) As Map
	Dim mapResult As Map
	Dim sZYH As String
	
	mapResult = Null
	For i = 0 To FBHData.Size - 1 
		mapResult = FBHData.Get(i)
		sZYH = mapResult.Get("ZYH")
		If sZYH = AZYH Then
			Exit
		End If
	Next
	Return mapResult
End Sub